package com.example.demo.task;

import com.example.demo.utils.QuartzUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Scheduler;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;


/**
 * @author Administrator
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class TaskRunner implements ApplicationRunner {

    private final Scheduler scheduler;

    @Override
    public void run(ApplicationArguments args) {
        System.out.println("开始任务。。。");
        String key = "key-";
        String desc = "desc-";
        for (int i = 0; i < 2; i++) {
            String id = key + i;
            String description = desc+i;
            String newCron = String.format("0/%d0 * * * * ?",i+1);
            //创建任务
            QuartzUtils.createScheduleJob(scheduler,newCron,id,description);
        }
    }
}
